var vm = new Vue({
	el: '#app',
	data: {
		username: '',
		password: '',
		captcha: '',
		rememberMe: false,
		error: false,
		errorMsg: '',
		src: $path+'captcha.jpg?t=' + guid()
	},
	methods: {
		refreshCode: function () {
			this.src = $path+"captcha.jpg?t=" + guid();
		},
		login: function () {
		
			//加密
			var username = Encrypt(vm.username ,'1234567890123456');
			var psw = Encrypt(vm.password ,'1234567890123456');
			var data = "username=" + vm.username + "&password=" + vm.password + "&captcha=" + vm.captcha+ "&rememberMe=" + vm.rememberMe+ "&language=" + i18n.language()+"&unique="+unique;
			$.ajax({
				type: "POST",
				url: $path+"sys/login",
				data: data,
				dataType: "json",
				success: function (result) {
					console.log(result);
					if (result.code == 0) {//登录成功
						window.localStorage.login = "login";
						window.localStorage.Authorization = result.Authorization;
						parent.location.href = 'index.html';
					} else {
						vm.error = true;
						vm.errorMsg = result.msg;
						vm.refreshCode();
						vm.password="";
						//alert(result.msg);
					}
				}
			});
				
		
		}
	}
	
});


function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function guid() {
   unique = (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
   console.log(unique);
   return unique;
}